import collections

class Solution(object):
    def orderlyQueue(self, s, k):
        if k == 1:
            min_s = s
            n = len(s)
            for i in range(n):
                s = s[1:] + s[0]
                min_s = min(min_s, s)
            return min_s
        else:
            c = collections.Counter(s)
            ans = []
            for key in range(26):
                word = chr(key + ord('a'))
                ans.append(word * c[word])
            return ''.join(ans)



data = Solution()
s = "cba"
k = 1
print(data.orderlyQueue(s, k))
